Enhance message building with media caching#15
Open
XGH2333 wants to merge 1 commit into
Open
Conversation
修改图片处理逻辑-将图片base64 作为附件传给 Gateway
Reviewer's GuideEnhances message-building to cache media and send image contents as base64 attachments to the Gateway, while avoiding redundant image references in the text message. Sequence diagram for enhanced message sending with media cachingsequenceDiagram
actor User
participant Plugin_onmessage as plugin_onmessage
participant MediaCache as saveMediaToCache
participant FileSystem as fs_cache
participant GatewayClient as gwClient
participant GatewayService as Gateway
User->>Plugin_onmessage: incoming_event
activate Plugin_onmessage
Plugin_onmessage->>Plugin_onmessage: extract text and extractedMedia
alt has_media
Plugin_onmessage->>MediaCache: saveMediaToCache(extractedMedia, ctx)
activate MediaCache
MediaCache->>FileSystem: write media files to cache
FileSystem-->>MediaCache: cached file paths
deactivate MediaCache
MediaCache-->>Plugin_onmessage: savedMedia
Plugin_onmessage->>Plugin_onmessage: build mediaInfo excluding images
Plugin_onmessage->>Plugin_onmessage: append mediaInfo to openclawMessage
Plugin_onmessage->>FileSystem: readFile for each m in savedMedia with path
FileSystem-->>Plugin_onmessage: image buffers
Plugin_onmessage->>Plugin_onmessage: encode to base64, guessMimeFromUrl
Plugin_onmessage->>Plugin_onmessage: build attachments array
else no_media
Plugin_onmessage->>Plugin_onmessage: use text only as openclawMessage
end
Plugin_onmessage->>GatewayClient: request chat.send(sessionKey, message, idempotencyKey, attachments)
activate GatewayClient
GatewayClient->>GatewayService: chat.send(payload with optional attachments)
GatewayService-->>GatewayClient: sendResult
deactivate GatewayClient
GatewayClient-->>Plugin_onmessage: sendResult
deactivate Plugin_onmessage
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In the attachments-building loop you log
[读取缓存图片失败]for any media type, but the loop may include non-image files as well; consider making the log message media-type agnostic or includingm.typefor clarity. - When constructing attachments you only compute
mimeTypeforimagetypes and leave itundefinedfor others; if the gateway expects or benefits from MIME types for files/voice/video as well, it may be safer to infer or pass appropriate MIME types for those too.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the attachments-building loop you log `[读取缓存图片失败]` for any media type, but the loop may include non-image files as well; consider making the log message media-type agnostic or including `m.type` for clarity.
- When constructing attachments you only compute `mimeType` for `image` types and leave it `undefined` for others; if the gateway expects or benefits from MIME types for files/voice/video as well, it may be safer to infer or pass appropriate MIME types for those too.
## Individual Comments
### Comment 1
<location path="src/index.ts" line_range="876-878" />
<code_context>
+ fileName: m.name,
+ content: b64,
+ });
+ } catch (e: any) {
+ logger?.warn(`[OpenClaw] 读取缓存图片失败: ${e.message}`);
+ }
+ }
</code_context>
<issue_to_address>
**suggestion:** Log message references images but the block handles all media types.
Since this catch applies to any `m.type`, but the message mentions only images ("读取缓存图片失败"), consider making the log text media-agnostic or including `m.type` so logs accurately reflect what failed.
```suggestion
} catch (e: any) {
logger?.warn(`[OpenClaw] 读取缓存媒体失败 (type: ${m.type}): ${e.message}`);
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+876
to
+878
| } catch (e: any) { | ||
| logger?.warn(`[OpenClaw] 读取缓存图片失败: ${e.message}`); | ||
| } |
There was a problem hiding this comment.
suggestion: Log message references images but the block handles all media types.
Since this catch applies to any m.type, but the message mentions only images ("读取缓存图片失败"), consider making the log text media-agnostic or including m.type so logs accurately reflect what failed.
Suggested change
| } catch (e: any) { | |
| logger?.warn(`[OpenClaw] 读取缓存图片失败: ${e.message}`); | |
| } | |
| } catch (e: any) { | |
| logger?.warn(`[OpenClaw] 读取缓存媒体失败 (type: ${m.type}): ${e.message}`); | |
| } |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

修改图片处理逻辑-将图片base64 作为附件传给 Gateway
Summary by Sourcery
Cache incoming media and send images as binary attachments instead of only text references when building and dispatching messages to the gateway.
Enhancements: